<template>
  <div>
    <obj-edit-ori ref="editRef" :loading="loading" :rules="rules" :span="edit_span" :width="edit_width" @fetch-data="getData" />
  </div>
</template>

<script lang="ts" setup>
import { ElLoading } from 'element-plus'
import { api_saas_detail } from '/@/api/obj'

//设置表名
const tablename = 'basic_apps'

//设置编辑页
const edit_width = '518px'
const edit_span = 13
const loading = reactive<any>({})
//设置必填项
const rules = reactive<any>({
  name: [{ required: true, trigger: 'blur', message: '请输入名称' }],
})

defineOptions({
  name: tablename,
})
const route: any = useRoute()
//通用变量
const editRef = ref<any>(null)
const config_table = ref<any>({})

//自定义变量

//自定义方法

//通用添加
const add = () => {
  editRef.value.showEdit(config_table.value)
}
//通用编辑
const edit = (row = {}) => {
  editRef.value.showEdit(row)
}
const getData = () => {
  api_saas_detail(tablename, { id: parseInt(`${route.query.edit}`) }).then((res: any) => {
    config_table.value = res.config_table
    if (res.detail) {
      edit(res)
    } else {
      add()
    }
  })
}
//通用加载前
onBeforeMount(() => {
  const load = ElLoading.service({
    lock: true,
    text: 'Loading',
    background: 'rgba(0, 0, 0, 0.7)',
  })
  Object.assign(loading, load)
  let i = true
  setInterval(function () {
    if (i && tablename) {
      i = false
      getData()
    }
  }, 1000)
})
</script>
